#include <stdarg.h>
#include "utils.h"
void print_error_msg_and_die(const char *s, ...)
{
	va_list valist;
        va_start(valist, s);
	const char *ps = NULL;
	while((ps=va_arg(valist,const char *))!= NULL){
		fprintf(stderr,"%s",ps);
		printf("%s",ps);
	}
        va_end(valist);
	exit(-1);
}

FILE *safe_fopen(const char *path, const char *mode)
{
        FILE *fp;
        if ((fp = fopen(path, mode)) == NULL)
                print_error_msg_and_die("%s", path);
        return fp;
}
void *safe_realloc(void *ptr, size_t size)
{
        ptr = realloc(ptr, size);
        if (ptr == NULL && size != 0)
                print_error_msg_and_die("bb_msg_memory_exhausted");
        return ptr;
}
void *safe_malloc(size_t size){
	void*p = malloc(size);
	if(p==NULL&&size!=0){
		print_error_msg_and_die("malloc err");
	}
	return p;
}


